﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using View.BookForms;

namespace View.MemberForms
{
    public partial class BookPicker : Form
    {

        private bool canClose = true;

        public BookPicker()
        {
            InitializeComponent();
        }

        public event EventHandler<BookEventArgs> Submit;

        private void OnSubmit()
        {
            canClose = true;
            if (dataGridViewBooks.SelectedRows.Count > 0)
            {
                var row = dataGridViewBooks.SelectedRows[0];
                int id = Int32.Parse(row.Cells["MBColumnId"].Value.ToString());

                if (row.Cells["ColumnBorrowed"].Value.ToString() == "Igen") {
                    MessageBox.Show("A k\u00F6nyvet m\u00E1r kik\u00F6lcs\u00F6n\u00F6zt\u00E9k!");
                    canClose = false;
                    return;
                }
                
                Submit(this, new BookEventArgs(id));
            }
            else
            {
                Submit(this, null);
            }

        }

        private void buttonOk_Click(object sender, EventArgs e)
        {
            OnSubmit();
            if (canClose)
            {
                Hide();
            }
        }

        private void BookPicker_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            Hide();
        }
    }
}
